package haoyc.config;

import haoyc.handler.*;
import haoyc.utils.MarshallingCodeCFactory;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;

/**
 * @author Memory
 * @version 1.0
 * @date 2021/12/13
 */

public class ServerChannelInitializer extends ChannelInitializer<NioSocketChannel> {

    @Override
    protected void initChannel(NioSocketChannel channel) {

        ChannelPipeline pipeline = channel.pipeline();
        try {
            pipeline.addLast("encoder", MarshallingCodeCFactory.buildMarshallingEncoder());
            pipeline.addLast("decoder", MarshallingCodeCFactory.buildMarshallingDecoder());
            pipeline.addLast("logging", new LoggingHandler(LogLevel.INFO));
            pipeline.addLast(new UserLoginServerHandler());
            pipeline.addLast(new MessageHandler());
            pipeline.addLast(new KeyEventHandler());
            pipeline.addLast(new MouseEventHandler());
        } catch (Exception e){
            e.printStackTrace();
        }
    }

}
